package com.yujie.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class WebUtils {
    /**
     * 将字符串渲染到客户端
     *
     * @param response 渲染对象
     * @return null
     */
    public static String renderString(HttpServletResponse response, R resultJson) {
        try {
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            ServletOutputStream outputStream = response.getOutputStream();
            outputStream.write(JSON.toJSONString(resultJson).getBytes());
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return null;
    }

}